var express = require("express");
const jwt = require("jsonwebtoken");
const router = express.Router();

/* GET home page. */
router.get("/", function (req, res, next) {
  console.log(req.query);
  res.json({
    code: 1,
    msg: "hello world",
  });
});

router.get("/jwt", (req, res) => {
  const { token } = req.query;
  jwt.verify(token, "secret", (err, decode) => {
    if (err) {
      res.json({
        code: 0,
        msg: "token失效",
      });
    } else {
      res.json({
        code: 1,
        msg: "success",
        data: decode,
      });
    }
  });
});

module.exports = router;
